package com.ce.pms.occupation;

import java.util.HashSet;
import java.util.Set;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.ce.pms.DBUnitTool;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.occupation.service.IPerfectItemDispatchService;
import com.ce.pms.occupation.vo.CompletePerfectItemVO;
import com.ce.pms.occupation.vo.PerItemDispSearchVO;
import com.ce.pms.occupation.vo.PerfectItemDispatchVO;
import com.ce.pms.occupation.vo.PerfectItemRequisitionVO;
import com.ce.util.BeanUtil;
import com.sitechasia.webx.core.support.Page;
/**
 * 功能描述: 整改项目派工Service測試类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2009-1-5
 * Edit author:
 * Edit on:
 * 修改原因：

 */

public class PerfectItemDispatchServiceImplT extends DBUnitTool {
	private static IPerfectItemDispatchService perfectItemDispatchService;
	/**
	 * 方法描述: 分页查询所有整改项目派工
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param contractorInfoId,SearchVO
	 * @return 返回当前页的查询结果
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testQueryPerfectItemDispatchVOByPage(){
		Long contractorInfoId = 1l;
		PerItemDispSearchVO searchVO = new PerItemDispSearchVO();
		searchVO.setContractorInfoId(contractorInfoId);
		Page page = perfectItemDispatchService.queryPerfectItemDispatchVOByPage(searchVO);
		Assert.assertNotNull(page.getResult());
	}
	/**
	 * 方法描述: 根据ID查询整改项目派工VO
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param id
	 * @return PerfectItemDispatchVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */

	public void testQueryperfectItemDispatchVOById() {
		Long id = 10001l;
		PerfectItemDispatchVO perfectItemDispatchVO = perfectItemDispatchService.queryperfectItemDispatchVOById(id);
		BeanUtil.printfInfo(perfectItemDispatchVO, true);
		Assert.assertNotNull(perfectItemDispatchVO);
	}
	/**
	 * 方法描述: 增加整改项目派工方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param perfectItemDispatchVO
	 * @return perfectItemDispatchVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */

	public void testAddPerfectItemDispatch(){
		PerfectItemDispatchVO perfectItemDispatchVO = new PerfectItemDispatchVO();
		perfectItemDispatchVO.setDispatchNumber(perfectItemDispatchService.generateOccupationCoding());
		perfectItemDispatchVO.setContractorInfoConfigId(10000l);
		perfectItemDispatchVO.setDispatchDate(perfectItemDispatchService.getDate());
		Set<PerfectItemRequisitionVO>  set = new HashSet<PerfectItemRequisitionVO>();
		PerfectItemRequisitionVO requisitionVO = new PerfectItemRequisitionVO();
		requisitionVO.setKeyword(4l);
		set.add(requisitionVO);
		perfectItemDispatchVO.setPerfectItemRequisitions(set);
		try {
			perfectItemDispatchVO = perfectItemDispatchService.addPerfectItemDispatch(perfectItemDispatchVO);
			Assert.assertNotNull(perfectItemDispatchVO);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "occupation:occupation_perfectItemDispatch_add_exception");
		}
	}
	/**
	 * 方法描述: 新增整改项目派工验证方法
	 * @author 胡煦
	 * Create on:2008-12-31
	 * @param perfectItemRequisitionId
	 * @return void
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testCheckAddIsTrue(){
		try {
			PerfectItemDispatchVO perfectItemDispatchVO = new PerfectItemDispatchVO();
			perfectItemDispatchService.checkAddIsTrue(perfectItemDispatchVO);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e,"occupation:occupation_perfectItemDispatch_add_exception");
		}
	}
	/**
	 * 方法描述: 修改整改项目派工验证方法
	 * @author 胡煦
	 * Create on:2008-12-31
	 * @param perfectItemDispatchId
	 * @return PerfectItemDispatchDO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testCheckEditIsTrue(){
		Long perfectItemDispatchId = 10001l;
		try {
			perfectItemDispatchService.checkEditIsTrue(perfectItemDispatchId);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e,"occupation:occupation_perfectItemDispatch_edit_exception");
		}

	}

	/**
	 * 方法描述: 修改整改项目派工方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param perfectItemDispatchVO
	 * @return perfectItemDispatchVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	@Test
	public void testEditPerfectItemDispatch(){
		PerfectItemDispatchVO perfectItemDispatchVO = perfectItemDispatchService.queryperfectItemDispatchVOById(10001l);
		Set<PerfectItemRequisitionVO>  set = new HashSet<PerfectItemRequisitionVO>();
		PerfectItemRequisitionVO requisitionVO = new PerfectItemRequisitionVO();
		PerfectItemRequisitionVO requisitionVO2 = new PerfectItemRequisitionVO();
		requisitionVO.setKeyword(4l);
		requisitionVO2.setKeyword(3l);
		set.add(requisitionVO);
		set.add(requisitionVO2);
		perfectItemDispatchVO.setPerfectItemRequisitions(set);
		try {
			perfectItemDispatchVO = perfectItemDispatchService.editPerfectItemDispatch(perfectItemDispatchVO);
			Assert.assertNotNull(perfectItemDispatchVO);
			set = perfectItemDispatchVO.getPerfectItemRequisitions();
			Assert.assertTrue(set.size() == 2);
			for(PerfectItemRequisitionVO itemRequisitionVO : set){
				Assert.assertTrue((itemRequisitionVO.getKeyword()== 3l)||(itemRequisitionVO.getKeyword()== 4l));
			}
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "occupation:occupation_perfectItemDispatch_edit_exception");
		}
	}
	/**
	 * 方法描述: 刪除整改项目派工验证方法
	 * @author 胡煦
	 * Create on:2008-12-31
	 * @param perfectItemDispatchId
	 * @return void
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testCheckDeleteIsTrue(){
		Long perfectItemDispatchId = 10001l;
		try {
			perfectItemDispatchService.checkDeleteIsTrue(perfectItemDispatchId);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "occupation:occupation_perfectItemDispatch_delete_exception");
		}
	}
	/**
	 * 方法描述: 刪除整改项目派工下的派工项目验证方法
	 * @author 胡煦
	 * Create on:2008-12-31
	 * @param perfectItemDispatchId
	 * @return void
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testCheckDeletePerfectItemIsTrue(){
		Long perfectItemRequisitionId = 3l;
		try {
			perfectItemDispatchService.checkDeletePerfectItemIsTrue(perfectItemRequisitionId);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e,"occupation:occupation_perfectItemTrack_requisition_delete_exception");
		}
	}
	/**
	 * 方法描述: 删除整改项目派工方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param perfectItemDispatchId
	 * @return boolean
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testDeletePerfectItemDispatch(){
		Long perfectItemDispatchId = 10001l;
		try {
			perfectItemDispatchService.deletePerfectItemDispatch(perfectItemDispatchId);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e,"occupation:system_delete_inused_exception");
		}
	}
	/**
	 * 方法描述: 完工登记方法
	 * @author 胡煦
	 * Create on:2009-1-4
	 * @param completePerfectItemVO
	 * @return boolean
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */

	public void registerCompPerItem(){
		CompletePerfectItemVO  completePerfectItemVO = new CompletePerfectItemVO();
		completePerfectItemVO.setCompleteDate(perfectItemDispatchService.getDate());
		completePerfectItemVO.setPerfectItemDispatchId(10003l);
		completePerfectItemVO.setTrackDate(perfectItemDispatchService.getDate());
		completePerfectItemVO.setTrackerId(1l);
		Set<Long> perItemReqIdSet = new HashSet<Long>();
		perItemReqIdSet.add(3l);
		completePerfectItemVO.setPerItemReqIdSet(perItemReqIdSet);
		boolean b = perfectItemDispatchService.registerCompPerItem(completePerfectItemVO);
		Assert.assertTrue(b);
	}
	/**
	 * 方法描述: 生成入伙派工单单号.规则如下
	 * PK+系统当前年月日+三位流水号
	 * @author 胡煦
	 * Create on:2009-1-4
	 * @param
	 * @return String
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void testGenerateOccupationCoding(){
		String string = perfectItemDispatchService.generateOccupationCoding();
		BeanUtil.printfInfo(string, true);
		Assert.assertNotNull(string);
	}
	/**
    *
    * 功能描述:   <br>
    *
    * Create author：胡煦  <br>
    * Create on:2008-12-17  <br>
    * Edit author：  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
	@BeforeClass
	public static void initPerfectItemRequisition(){
		if (perfectItemDispatchService == null) {
			perfectItemDispatchService = (IPerfectItemDispatchService)DBUnitTool.applicationContext.getBean("perfectItemDispatchService");
		}
	}
}
